<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#box1{
				height: 100px;
				width: 100px;
				background-color: red ;
				position: absolute;
				top:0;
				
			}
		</style>
	</head>
	<body>
		<div id="box1"></div>
		<script type="text/javascript">
			var box = document.getElementById("box1");
			var speed = 10;
			var dir = 0;
			var dic = 1;
			var timer;
			timer = setInterval(function(){
				//当用户按了strl之后，速度会加快
				if(dic == 0){
					speed = 50;
				}else{
					speed = 10 ;
				}
				switch(dir){
					case 37:
						box.style.left = box.offsetLeft - speed + "px";
						break;
					case 39:
						box.style.left = box.offsetLeft + speed + "px";
						break;
					case 38:
						box.style.top = box.offsetTop - speed + "px";
						break;
					case 40:
						box.style.top = box.offsetTop + speed + "px";
						break;
				}
			},30)
			document.onkeydown = function(){
				event = event || window.event;
				dir = event.keyCode;
				if(event.ctrlKey){
					dic = 0;
				}else{
					dic = 1;
				}
			}
			document.onkeyup = function(){
				dir = 0;
			}
		</script>
	</body>
</html>
